home *** CD-ROM | disk | FTP | other *** search
/ TPUG - Toronto PET Users Group / TPUG Users Group CD / TPUG Users Group CD.iso / AMIGA / AMICUS / AMICUS01.ADF / ABasicStuff / Tools / CardFile.bas < prev    next >
BASIC Source File  |  1985-12-04  |  15KB  |  502 lines

  1.                  ***/
  2. /*****************************************/
  3. /*****************************************/
  4.  
  5.    i3 = 5;
  6.  
  7.    printf("\n\n50,000 floats of %d (Compiler Interface)\n", i3 );
  8.    for( dots_good = 0, i= 1; i < 50000; i++ )
  9.    {
  10.        k4.num4 = (FLOAT) i3;
  11.       show_dot();
  12.    }
  13.    show_result( k4.num4 );
  14.  
  15.  
  16.    printf("\n\n50,000 floats of %d (Function Interface)\n", i3 );
  17.    for( dots_good = 0, i= 1; i < 50000; i++ )
  18.    {
  19.        k4.i4 = SPFlt(i3);
  20.       show_dot();
  21.    }
  22.    show_result_ffp( k4.i4 );
  23.  
  24.  
  25. /*****************************************/
  26. /*****************************************/
  27. /***                                   ***/
  28. /***  COMPILER & FFP S.P. NEGATION     ***/
  29. /***                                   ***/
  30. /*****************************************/
  31. /*****************************************/
  32.  
  33.    k1.num1 = PI;
  34.    k2.num2 = k1.num1 - PIME;
  35.  
  36.    printf("\n\n50,000 negates of %s (Compiler Interface)\n", st2 );
  37.    for( dots_good = 0, i= 1; i < 50000; i++ )
  38.    {
  39.       k4.num4 = -k2.num2;
  40.       show_dot();
  41.    }
  42.    show_result( k4.num4 );
  43.  
  44.  
  45.    k1.i1 = SPFieee(k1.i1);
  46.    k2.i2 = SPFieee(k2.i2);
  47.  
  48.    printf("\n\n50,000 negates of %s (Function Interface)\n", st2 );
  49.    for( dots_good = 0, i= 1; i < 50000; i++ )
  50.    {
  51.       k4.i4 = SPNeg(k2.i2);
  52.       show_dot();
  53.    }
  54.    show_result_ffp( k4.i4 );
  55.  
  56.  
  57. /*****************************************/
  58. /*****************************************/
  59. /***                                   ***/
  60. /***  COMPILER & FFP S.P. ABSOLUTE VAL ***/
  61. /***                                   ***/
  62. /*****************************************/
  63. /*****************************************/
  64.  
  65.    k1.num1 = PI;
  66.    k4.num4 = PIME - k1.num1;
  67.  
  68.    printf("\n\n50,000 absolute values of %f (Compiler Interface)\n", k4.num4 );
  69.    for( dots_good = 0, i= 1; i < 50000; i++ )
  70.    {
  71.       k5.num5 = fabs(k4.num4);
  72.       show_dot();
  73.    }
  74.    show_result( k5.num5 );
  75.  
  76.  
  77.    printf("\n\n50,000 absolute values of %f (Function Interface)\n", k4.num4 );
  78.    k4.i4 = SPFieee(k4.i4);
  79.    for( dots_good = 0, i= 1; i < 50000; i++ )
  80.    {
  81.       k5.i5 = SPAbs(k4.i4);
  82.       show_dot();
  83.    }
  84.    show_result_ffp( k5.i5 );
  85.  
  86.  
  87.    printf("\n\n*** HIT RETURN TO CONTINUE ***");   getch();
  88.  
  89.  
  90. /*****************************************/
  91. /*****************************************/
  92. /***                                   ***/
  93. /***  COMPILER & FFP S.P. COMPARE      ***/
  94. /***                                   ***/
  95. /*****************************************/
  96. /*****************************************/
  97.  
  98.    k1.num1 = PI;
  99.    k2.num2 = k1.num1 - PIME;
  100.  
  101.    if (k2.num2 >= k1.num1)
  102.       printf("\n\n%f is greater than or equal to %f (Compiler Interface)\n", k2.num2, k1.num1);
  103.    else
  104.       printf("\n\n%f is less than %f (Compiler Interface)\n", k2.num2, k1.num1);
  105.  
  106.  
  107.    k1.i1 = SPFieee(k1.i1);
  108.    k2.i2 = SPFieee(k2.i2);
  109.  
  110.    printf("\n*** SPCmp(k2.i2, k1.i1) returned %d ***", SPCmp(k2.i2, k1.i1));
  111.  
  112.  
  113.    if (SPCmp(k2.i2, k1.i1))     /* V1.0 FFP Bug.  SPCmp() broken. */
  114.  
  115.    {  k1.num1 = PI;
  116.       k2.num2 = k1.num1 - PIME;
  117.       printf("\n\n%f is greater than or equal to %f (Function Interface)\n", k2.num2, k1.num1);
  118.    }
  119.    else
  120.    {  k1.num1 = PI;
  121.       k2.num2 = k1.num1 - PIME;
  122.       printf("\n\n%f is less than %f (Function Interface)\n", k2.num2, k1.num1);
  123.    }
  124.  
  125.  
  126.    if (k1.num1 >= k2.num2)
  127.       printf("\n\n%f is greater than or equal to %f (Compiler Interface)\n", k1.num1, k2.num2);
  128.    else
  129.       printf("\n\n%f is less than %f (Compiler Interface)\n", k1.num1, k2.num2);
  130.  
  131.  
  132.    k1.i1 = SPFieee(k1.i1);
  133.    k2.i2 = SPFieee(k2.i2);
  134.  
  135.    if (SPCmp(k1.i1, k2.i2))
  136.    {  k1.num1 = PI;
  137.       k2.num2 = k1.num1 - PIME;
  138.       printf("\n\n%f is greater than or equal to %f (Function Interface)\n", k1.num1, k2.num2);
  139.    }
  140.    else
  141.    {  k1.num1 = PI;
  142.       k2.num2 = k1.num1 - PIME;
  143.       printf("\n\n%f is less than %f (Function Interface)\n", k1.num1, k2.num2);
  144.    }
  145.  
  146.  
  147. /*******************************FP lib pointer */
  148. int MathTransBase;   /* Transcendental FFP lib pointer */
  149.  
  150. int dots_good = 0;
  151.  
  152.  
  153. union kludge1        /* Can't use FLOAT directly for FFP stuff */
  154. {                    /* because V1.0 Lattice converts FLOAT to */
  155.   FLOAT num1;        /* DOUBLE in expressions and when passing */
  156.   int   i1;          /* parameters.                            */
  157. } k1;
  158.  
  159. union kludge2
  160. {
  161.   FLOAT num2;
  162.   int   i2;
  163. } k2;
  164.  
  165. union kludge3
  166. {
  167.   FLOAT num3;
  168.   int   i3;
  169. } k3;
  170.  
  171. union kludge4
  172. {
  173.   FLOAT num4;
  174.   int   i4;
  175. } k4;
  176.  
  177. union kludge5
  178. {
  179.   FLOAT num5;
  180.   int   i5;
  181. } k5;
  182.  
  183. union kludge6
  184. {
  185.   FLOAT num6;
  186.   int   i6;
  187. } k6;
  188.  
  189.  
  190.  
  191. show_dot() { if( ++dots_good == 1000) { dots_good = 0; printf(".");} }
  192.  
  193.  
  194.  
  195. show_result( num ) FLOAT num; { printf("\nResult = %f", num); }
  196.  
  197.  
  198.  
  199. show_result_ffp(in_val)   /* Convert to IEEE and display */
  200.   int in_val;
  201. {
  202.   union kludge_sr
  203.   {
  204.     FLOAT new_iv_f;
  205.     int   new_iv_i;
  206.   } k;
  207.  
  208.   k.new_iv_i = SPTieee(in_val);
  209.   show_result(k.new_iv_f);
  210. }
  211.  
  212.  
  213.  
  214.  
  215. main()                  /* Lattice/FFP test code */
  216. {
  217.    UWORD i;
  218.    int i3;
  219.  
  220.    printf("C-ROM & Shared RAM Library Test Facility for the Amiga-Lattice Basic/Trans Math Libraries");
  221.  
  222. /*****************************************/
  223. /*****************************************/
  224. /***                                   ***/
  225. /***  OPEN ROM AND RAM FFP LIBRARIES   ***/
  226. /***                                   ***/
  227. /*****************************************/
  228. /*****************************************/
  229.  
  230.    if((MathBase = OpenLibrary("mathffp.library", 0)) < 1 ) {
  231.        printf("\n\n*** ERROR ***  Can't open mathffp.library: vector = %lx\n", MathBase);
  232.        exit();
  233.    }
  234.    else {
  235.        printf("\n\nSuccessfully opened mathffp.library: vector = %lx\n", MathBase);
  236.    }
  237.  
  238.    if((MathTransBase = OpenLibrary("mathtrans.library", 0)) < 1 ) {
  239.        printf("\n\n*** ERROR ***  Can't open mathtrans.library: vector = %lx\n", MathTransBase);
  240.        CloseLibrary(MathBase);
  241.        exit();
  242.    }
  243.    else {
  244.        printf("\n\nSuccessfully opened mathtrans.library: vector = %lx\n", MathTransBase);
  245.    }
  246.  
  247.  
  248. /*****************************************/
  249. /*****************************************/
  250. /***                                   ***/
  251. /***  COMPILER & FFP S.P. ADDITION     ***/
  252. /***                                   ***/
  253. /*****************************************/
  254. /*****************************************/
  255.  
  256.    k1.num1 = PI;                  /* V1.0 Lattice C BUG!  Can't have two  */
  257.    k2.num2 = k1.num1 - PIME;      /* constant assignments in a row.  Fake */
  258.                                   /* it by making the second be an        */
  259.                                   /* expression!                          */
  260.  
  261.  
  262.    printf("\n\n50,000 additions of %s to %s (Compiler Interface)\n", st1, st2);
  263.    for( dots_good = 0, i= 1; i < 50000; i++ )
  264.    {
  265.       k3.num3 = k1.num1 + k2.num2;
  266.       show_dot();
  267.    }
  268.    show_result( k3.num3 );
  269.  
  270.  
  271.    k1.i1 = SPFieee(k1.i1);
  272.    k2.i2 = SPFieee(k2.i2);
  273.  
  274.    printf("\n\n50,000 additions of %s to %s (Function Interface)\n", st1, st2 );
  275.    for( dots_good = 0, i= 1; i < 50000; i++ )
  276.    {
  277.       k3.i3 = SPAdd(k2.i2, k1.i1);
  278.       show_dot();
  279.    }
  280.    show_result_ffp( k3.i3 );
  281.  
  282.  
  283. /*****************************************/
  284. /*****************************************/
  285. /***                                   ***/
  286. /***  COMPILER & FFP S.P. SUBTRACTION  ***/
  287. /***                                   ***/
  288. /*****************************************/
  289. /*****************************************/
  290.  
  291.    k1.num1 = PI;
  292.    k2.num2 = k1.num1 - PIME;
  293.  
  294.    printf("\n\n50,000 subtractions of %s from %s (Compiler Interface)\n", st1, st2 );
  295.    for( dots_good = 0, i= 1; i < 50000; i++ )
  296.    {
  297.       k3.num3 = k2.num2 - k1.num1;
  298.       show_dot();
  299.    }
  300.    show_result( k3.num3 );
  301.  
  302.  
  303.    k1.i1 = SPFieee(k1.i1);
  304.    k2.i2 = SPFieee(k2.i2);
  305.  
  306.    printf("\n\n50,000 subtractions of %s from %s (Function Interface)\n", st1, st2 );
  307.    for( dots_good = 0, i= 1; i < 50000; i++ )
  308.    {
  309.       k3.i3 = SPSub(k1.i1, k2.i2);
  310.       show_dot();
  311.    }
  312.    show_result_ffp( k3.i3 );
  313.  
  314.    
  315. /*****************************************/
  316. /*****************************************/
  317. /***                                   ***/
  318. /***  COMPILER & FFP S.P. MULTIPLYS    ***/
  319. /***                                   ***/
  320. /*****************************************/
  321. /*****************************************/
  322.  
  323.    k1.num1 = PI;
  324.    k2.num2 = k1.num1 - PIME;
  325.  
  326.    printf("\n\n50,000 multiplies of %s by %s (Compiler Interface)\n", st1, st2 );
  327.    for( dots_good = 0, i= 1; i < 50000; i++ )
  328.    {
  329.       k3.num3 = k1.num1 * k2.num2;
  330.       show_dot();
  331.    }
  332.    show_result( k3.num3 );
  333.    
  334.  
  335.    k1.i1 = SPFieee(k1.i1);
  336.    k2.i2 = SPFieee(k2.i2);
  337.  
  338.    printf("\n\n50,000 multiplies of %s by %s (Function Interface)\n", st1, st2 );
  339.    for( dots_good = 0, i= 1; i < 50000; i++ )
  340.    {
  341.       k3.i3 = SPMul(k2.i2, k1.i1);
  342.       show_dot();
  343.    }
  344.    show_result_ffp( k3.i3 );
  345.  
  346.  
  347. /*****************************************/
  348. /*****************************************/
  349. /***                                   ***/
  350. /***  COMPILER & FFP S.P. DIVISION     ***/
  351. /***                                   ***/
  352. /*****************************************/
  353. /*****************************************/
  354.  
  355.    k1.num1 = PI;
  356.    k2.num2 = k1.num1 - PIME;
  357.  
  358.    printf("\n\n50,000 divides of %s by %s (Compiler Interface)\n", st1, st2 );
  359.    for( dots_good = 0, i= 1; i < 50000; i++ ) bit IEEE format running in a somewhat 
  360. simpler exception handling environment.
  361.  
  362. Motorola Fast Floating Point format is available (in 32 bits only) in two 
  363. standard libraries.  The fundamental math routines are in the library mathffp 
  364. which resides in the Writeable Control Store.  The corresponding 
  365. transcendental functions are in the library mathtrans which is disk-based 
  366. (i.e., it's found in the LIBS: directory and is brought into memory and 
  367. shared between programs as needed).
  368.  
  369. To access routines in these libraries you do an OpenLibrary() call and then 
  370. call the desired routine using one of the interface entrypoints defined in 
  371. amiga.lib.
  372.  
  373. Yes, we are working with Lattice to make the 32 bit IEEE format and the 32 
  374. bit Motorola format routines directly available from the language.
  375.  
  376. We do not expect to make the Amiga schematics public anytime soon.  There 
  377. will, however, be more info available about the timing and characteristics of 
  378. the expansion bus.  
  379.  
  380.  
  381. From bobp@amiga.UUCP (Robert S. Pariseau) Tue Nov  5 21:53:01 1985
  382. Path: gumby!uwvax!seismo!lll-crg!ucdavis!ucbvax!decvax!decwrl
  383.             !pyramid!amiga!bobp
  384. From: bobp@amiga.UUCP (Robert S. Pariseau)
  385. Date: 6 Nov 85 03:53:01 GMT
  386. Reply-To: bobp@snake.UUCP (Robert S. Pariseau)
  387. Organization: Commodore-Amiga Inc., 983 University Ave #D, Los Gatos CA 95030
  388.  
  389. TITLE:  LatFFP program SOURCE (LONG!)
  390.  
  391. The program below shows how to access the Motorola Fast Floating Point 
  392. libraries from V1.0 release Lattice C for the Amiga.  As you will see when 
  393. you run it, the performance improvement gained by using the FFP routines 
  394. (even in this kludgey fashion) is generally around a factor of 10!
  395.  
  396. Part of that improvement is just the difference in precision.  The Lattice 
  397. stuff provides a 64 bit software implementation of the IEEE format.  The FFP 
  398. stuff provides a 32 bit implementation of the Motorola format.
  399.  
  400. The variables used for FFP math are defined as ints.  You can't use FLOATs 
  401. because V1.0 Lattice C converts FLOAT to DOUBLE during expression evaluation 
  402. and when passing arguments.
  403.  
  404. ------------------------Program Notes:
  405.  
  406. The program will compile and link cleanly using the stuff on the standard 
  407. V1.0 Lattice C for Amiga disk.  The Make script in the examples directory 
  408. will do all the work for you.  Since my C disk is rather full, and since I 
  409. like the dramatic increase in speed, I usually do my work in ram disk as 
  410. follows:
  411.  
  412.   1> cd df1:                               [my C disk]
  413.   1> copy examples/Make to :               [more convenient in root]
  414.   
  415.   1> copy LatFFP.c to ram:
  416.   1> execute Make ram:LatFFP
  417.   1> copy ram:LatFFP to df1:
  418.  
  419. I've also added a "stack 20000" command in my startup script 
  420. (s/startup-sequence) to make sure I don't have to worry about stack overflows.
  421.  
  422. The program shows 3 bugs in the V1.0 stuff and includes one kludge. The bugs 
  423. and kludge are maked in the source.  
  424.  
  425. Bug (1): V1.0 Lattice C doesn't properly handle successive assignments of 
  426. constants.  Use expressions.  
  427.  
  428. Bug (2): V1.0 FFP doesn't correctly return a result from SPCmp().  Fake it 
  429. with subtraction and SPTst() or write your own compare for now.  
  430.  
  431. Bug (3): V1.0 FFP doesn't correctly return the cosine result from SPSincos(). 
  432.  Use SPCos() instead.
  433.  
  434. The kludge is the set of union definitions so that we can use the same 
  435. variables for related Lattice and FFP expressions and for the conversions in 
  436. and out of IEEE format.  Note that we use the Lattice IEEE based routines in 
  437. printf() to get our output.
  438.  
  439. Note however, that the conversion routines are in the RAM based MathTrans 
  440. library.  Therefore, if you only want to use the WCS based MathFFP library, 
  441. you are on your own for conversion.
  442.  
  443. ------------------------Program Source Follows:
  444. #endif FOOIE
  445.  
  446.  
  447. /***********************************************************************
  448.  *  LatFFP -- Program to show the use of Motorola Fast Floating Point
  449.  *            math libraries with V1.0 Lattice C for the Amiga in
  450.  *            comparison to the DOUBLE precision IEEE floating point
  451.  *            math which is built in to the C.  The FFP format is
  452.  *            a 32 bit format.
  453.  *
  454.  *  Larry Hildenbrand -- Nov. 4, 1985
  455.  *  Bob Pariseau      -- Nov. 4, 1985  (minor editorial corrections)
  456.  *
  457.  ***********************************************************************/
  458.  
  459. #include <exec/types.h>
  460. #include <math.h>
  461.  
  462.  
  463. /* ??? #define   E      2.718281828459045 */  /* V1.0 Lattice C BUG!  See */
  464. #define   PIME   0.423310826                  /* below.  PIME == PI - E.  */
  465.  
  466.  
  467. /****  MAY BE BROKEN OUT INTO SEPARATE #include FILE ****/
  468.  
  469. extern   int     SPFix();
  470. extern   int     SPFlt();
  471. extern   int     SPCmp();
  472. extern   int     SPTst();
  473. extern   int     SPAbs();
  474. extern   int     SPNeg();
  475. extern   int     SPAdd();
  476. extern   int     SPSub();
  477. extern   int     SPMul();
  478. extern   int     SPDiv();
  479.  
  480. extern   int     SPAtan();
  481. extern   int     SPSin();
  482. extern   int     SPCos();
  483. extern   int     SPTan();
  484. extern   int     SPSincos();
  485. extern   int     SPSinh();
  486. extern   int     SPCosh();
  487. extern   int     SPTanh();
  488. extern   int     SPExp();
  489. extern   int     SPLog();
  490. extern   int     SPPow();
  491. extern   int     SPSqrt();
  492. extern   int     SPTieee();
  493. extern   int     SPFieee();
  494.  
  495. /********************************************************/
  496.  
  497.  
  498. char st1[80] = "3.1415926535897";
  499. char st2[80] = "2.718281828459045";
  500.  
  501.  
  502. int MathBase;        /* Basic Fqponmlkjihgfedcba`_^]\[ZYXWVUTSRQPONMLKJIHGFEDCBA